/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.chl.dat076.datesite.controllers;

import edu.chl.dat076.datesite.ejbs.UserEJBLocal;
import edu.chl.dat076.datesite.entities.Gender;
import edu.chl.dat076.datesite.entities.PartnerCriteria;
import edu.chl.dat076.datesite.entities.SiteUser;
import java.io.Serializable;
import java.util.ArrayList;
import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;

/**
 *
 * @author Daniel
 * @author Mikey
 */
@ManagedBean
@ViewScoped
public class SearchControllerBean implements Serializable {

    @EJB
    private UserEJBLocal userJPACtrl;

    private ArrayList<SiteUser> users;
    private Gender male = Gender.MALE;
    private Gender female = Gender.FEMALE;
    private PartnerCriteria criteria;
    
    /**
     * Default partner criteria for search
     */
    @PostConstruct
    public void postConstruct() {
        users = (ArrayList<SiteUser>) userJPACtrl.getAllUsers();
        criteria = new PartnerCriteria(18, 45, 150, 210, true, true);
    }
    
    public ArrayList<SiteUser> getUsers() {
        return users;
    }
    
    public String search() {
        FacesContext.getCurrentInstance().getExternalContext().getRequestMap()
                .put("results", userJPACtrl.searchUsers(null, criteria));
        return "onSearch";
    }

    public PartnerCriteria getCriteria() {
        return criteria;
    }
    
    public Gender getMale(){
        return male;
    }
    
    public Gender getFemale(){
        return female;
    }
}
